<%@page import="com.netistate.pojo.Project"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="com.netistate.pojo.User"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>project</title>
     <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/default.css" />
    <script type="text/javascript"  src="${pageContext.request.contextPath}/js/jquery-min.js"></script> 
    <script type="text/javascript"  src="${pageContext.request.contextPath}/js/common.js"></script>
    <script type="text/javascript"  src="${pageContext.request.contextPath}/js/table.js"></script>
    <script type="text/javascript"  src="${pageContext.request.contextPath}/plugin/msgbox/msgbox.js"></script>
    <script type="text/javascript"  src="${pageContext.request.contextPath}/jsp/project/project.js"></script>
    <script type="text/javascript"  src="${pageContext.request.contextPath}/plugin/calendar/Calendar.js"></script>
    <style type="text/css">
		.overTd {table-layout:fixed}
		.overTd td{text-overflow:ellipsis;overflow:hidden;white-space:nowrap;padding:0px}
    </style>
  </head>
  <body>
	    <div class="toolbar" >
		    <a href="#" class='buttonlink txbtip' title='添加项目' onclick="add()"><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/plus.png'/>添加项目</a>  
		    <a href="#" id="queryProjectButton" class='buttonlink txbtip' onclick="notHiddenDiv()" title='项目查询'><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/plus.png'/>项目查询</a>  
		</div>
		<div id="projectQuery" name="projectQuery" class="toolbar" style="display:block;overflow:hidden;">
		    <form id="queryProjectByCondition" name="projectQuery_condition" action="queryProjectByCondition.action" method="post" >
		        <table>
		           <tr>
		                <td class="td_title" title="项目管理者"><img alt="" src="${pageContext.request.contextPath}/images/common/save.gif">项目管理者：</td>
		                <td class="td_title">
		                    <select id="createProject" name="projectManager" style="width:100px;">
								<%	List<User> userList = (List<User>)request.getSession().getAttribute("userList");
									String queryProjectManager = (String)request.getAttribute("queryProjectManager");
									User queryProjectManagerUser = (User)request.getAttribute("queryProjectManagerUser");
									if("所有".equals(queryProjectManager) || queryProjectManager == null){%>
									<option title="所有" selected value="所有">所有</option>
								<%		for(User u : userList){ %>
										<option value="<%=u.getUsername()%>"><%=u.getRealName()%></option>
								<%		}
									}else{ %>
									<option title="所有" selected value="所有">所有</option>
								<%		for(User u : userList){
											if(queryProjectManagerUser.getUsername().equals(u.getUsername())){%>
											<option selected value="<%=queryProjectManagerUser.getUsername()%>"><%=queryProjectManagerUser.getRealName()%></option>
								<%			}else{%>
									<option value="<%=u.getUsername()%>"><%=u.getRealName()%></option>
								<%			}
										}
									}	%>
		                    </select>
		                </td>
		                <td title="时间">时间：</td>
		                <td>
							<%	Date date = new Date();
							    SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy-MM-dd");
							    String endString = sdFormat.format(date);
							    Calendar calendar = Calendar.getInstance();
							    calendar.setTime(date);
							    calendar.add(Calendar.DATE,-30);
							    Date date2 = calendar.getTime();
							    String startString = sdFormat.format(date2);
							    String dayStart = (String)request.getAttribute("queryProjectStarttime");
							    String dayEnd = (String)request.getAttribute("queryProjectEndtime");
							    if(dayStart != null){
							         startString = dayStart;
							    }
							    if(dayEnd != null){
							         if(endString.equals(dayEnd)){
							             endString = "现在";
							         }else{
							              endString = dayEnd;
							         }
							    }else{
							        endString = "现在";
							    }
							 %>
							<input id="dayStart" name="starttime" type="text" style="width:80px" onclick="MyCalendar.SetDate(this)" value="<%=startString %>" readonly="readonly" />
							</td>
							<td title="到">到</td>
							<td><input id="dayEnd" name="endtime" type="text" style="width:80px" onclick="MyCalendar.SetDate(this)" value="<%=endString %>" readonly="readonly" /></td>
		                	<td title="项目阶段">项目阶段：</td>
			                <td>
			                    <select id="statuesProject" name="projectProcess">
			                 	<%	String queryProjectProcess = (String)request.getAttribute("queryProjectProcess");
			                        if(queryProjectProcess == null){ %>
			                           <option value="所有">所有</option>
				                       <option value="售前">售前</option>
									   <option value="已签单">已签单</option>
									   <option value="实施">实施</option>
									   <option value="已验收">已验收</option>
									   <option value="停滞">停滞</option>
			                    <%	}else{ %>
			                            <option value="<%=queryProjectProcess %>"><%=queryProjectProcess %></option>
			                    <%		if(!"所有".equals(queryProjectProcess)){ %>
			                            	<option value="所有">所有</option>
			                    <%		}
			                            if(!"售前".equals(queryProjectProcess)){ %>
			                                 <option value="售前">售前</option>
			                    <%		}
			                            if(!"已签单".equals(queryProjectProcess)){ %>
			                                 <option value="已签单">已签单</option>
			                    <%		}
			                            if(!"实施".equals(queryProjectProcess)){ %>
			                                 <option value="实施">实施</option>
			                    <%		}
			                            if(!"已验收".equals(queryProjectProcess)){ %>
			                                 <option value="已验收">已验收</option>
			                    <%		}
			                            if(!"停滞".equals(queryProjectProcess)){ %>
			                                 <option value="停滞">停滞</option>
			                    <%		}
			                        }%>
			                    </select>
			                </td>
			                <td><input type="submit" value="查询" title="查询"/></td>
		           </tr>
		        </table>
		    </form>
		</div>
		
		<div id="rcon_onepage" style="width:100%;height:93%; overflow-y:scroll;overflow-x:no; border:1px solid;" >
			<table id="ptableSourt" width="100%" border="0" cellpadding="0" cellspacing="1"  class="resizable overTd">
				<thead>
					<tr class="fixHead">
						<td  class="td1" style="cursor:default" width="10%">项目名称</td>
						<td  class="td1" style="cursor:default" width="10%">项目管理员</td>
						<td  class="td1" style="cursor:pointer" width="24%">项目描述</td>
						<td  class="td1" style="cursor:default" width="10%">创建日期</td>
						<td  class="td1" style="cursor:default" width="6%">项目阶段</td>
						<td  class="td1" style="cursor:default" width="10%">客户名称</td>
						<td  class="td1"  width="8%">查看服务记录表</td>
						<td  class="td1" width="8%">查看技术备忘录</td>
						<td  class="td1"  colspan="3">操作</td>
					</tr>
				</thead>
				<%
					List<Project> list = new ArrayList<Project>();
					List<Project> plist = (List<Project>)request.getAttribute("pl");
					if(plist == null){
						list = (List<Project>)request.getSession().getAttribute("projectListInOneMonth");
					}else{
						list = plist;
					}
					for(Project p : list){
				 %>
			       <tr style="empty-cells:show;border-collapse:collapse;" onMouseOver= "this.bgColor   =   '#cccccc '; "   onMouseOut= "this.bgColor   =   '#FFFFFF'; " >  
				       <td title="<%=p.getProjectName() %>" align="center" class="td2 txbtip" >
				       	<a href="javascript:;" onclick="selectProject(<%=p.getId()%>)">&nbsp;<%=p.getProjectName() %></a>	
				       </td>
				       <td title="<%=p.getProjectManager() %>" align="center" class="td2 txbtip" >&nbsp;<%=p.getProjectManager() %></td>
				       <td title="<%=p.getDescr() %>" style="text-overflow:ellipsis;overflow:hidden;" align="left" style="cursor: hand;" ondblclick="show_project_detail(<%=p.getId()%>)" class="td2 txbtip" >&nbsp;<%=p.getDescr() %></td>
				       <td title="<%=p.getCreatetime() %>" align="center" class="td2 txbtip" >&nbsp;<%=p.getCreatetime() %></td>
				       <td title="<%=p.getProjectProcess() %>" align="center" class="td2 txbtip" >
				       	<%if(p.getProjectProcess() == null || "null".equals(p.getProjectProcess())){ %>
		       			-&nbsp;
		       			<%}else{ %>
		       			<%=p.getProjectProcess()%>&nbsp;
		       			<%} %>
				       </td>
				       <td title="<%=p.getClientName() %>" align="center" class="td2 txbtip" >
				       	<%if(p.getClientName() == null || "null".equals(p.getClientName())){ %>
		       			-&nbsp;
		       			<%}else{ %>
		       			<%=p.getClientName()%>&nbsp;
		       			<%} %>
				       </td>
				       <td title="" align="center" class="td2 txbtip" >	
				       		<a href="#" class='buttonlink txbtip' title='查看服务记录表' onclick="selectProject(<%=p.getId()%>)"><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/opera.png'/></a>
				       </td>
				       <td title="" align="center" class="td2 txbtip" >
				       		<a href="#" class='buttonlink txbtip' title='查看技术备忘录' onclick="show_project_techNote(<%=p.getId()%>)"><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/search.png'/></a>
				       </td>
				       		<%	User u = (User)request.getSession().getAttribute("session_user");
				       			if(u.getUsername().equals("admin") || p.getProjectManager().equals(u.getUsername())){
				       		 %>
					          <td align="center" class="td3 txbtip">
							     <a href="#" class='buttonlink txbtip' title='修改' onclick="edit(<%=p.getId()%>)"><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/edit.png'/></a>
						      </td>
						      <td align="center" class="td3 txbtip">
							      <a href="#" class='buttonlink txbtip' title='删除' onclick="del('<%=p.getId()%>','删除项目会删除与此项目关联的所有信息，您确定要删除？')" ><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/delete.png'/></a>
						      </td>
						      <%
						      	}else{
						       %>
				          		<%} %>
					   <td align="center" class="td3 txbtip">
						<a href="showLog.action?id=<%=p.getId()%>" target="_blank" class='buttonlink txbtip' title='预览日志'><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/gtk_print_preview.png'/></a>
					  </td>
			      </tr>
			 <%} %>
			</table>
		</div>
		
		<script type="text/javascript" >
		//点击具体某个项目时,并默认查找服务记录表
		function selectProject(id){
			AjaxUtil.request({
				url : 'selectProject.action',
				params : {id:id},
				success : function(responseText){
					window.parent.document.getElementById("mainFrame").src="${pageContext.request.contextPath}/jsp/project/project_id.jsp?id="+id;
				},
				failure : function(){
				}
			});
		}
		
		//查看当前项目下的技术备忘录
		function show_project_techNote(projectTechNoteId){
			AjaxUtil.request({
				url : 'look_project_techNote.action',
				params : {projectTechNoteId:projectTechNoteId},
				success : function(responseText){
					window.parent.document.getElementById("mainFrame").src="${pageContext.request.contextPath}/jsp/project/project_techNote.jsp?id="+projectTechNoteId;
				},
				failure : function(){
				}
			});
			
		};
		
		//添加项目
	    function add(){
	    	PigossMsg.show("${pageContext.request.contextPath}/jsp/project/addProject.jsp","添加项目",470,480,"AddProject.saveConfig()");
	    }
	    //编辑项目
	    function edit(id){
	  		AjaxUtil.request({
				url : 'editProject.action',
				params : {id:id},
				success : function(responseText){
					PigossMsg.show("${pageContext.request.contextPath}/jsp/project/editProject.jsp","修改项目",470,480,"EditProject.editConfig()");
				},
				failure : function(){
					PigossMsg.alert("修改失败!");
				}
			});
	        
	    }
	    //删除项目（级联部分未完成）
	    function del(id,msg){
	    	PigossMsg.confirm(msg,null,function yesHandler(){EditProject.del(id)},function noHandler(){});
	    	//PigossMsg.alert("不允许删除！");
	        /* this.msg = msg;
	        PigossMsg.confirm(this.msg,null,function yesHandler(){EditProject.del(id)},function noHandler(){}); */
	    }
	    //切换查询条件
	    function notHiddenDiv(){
	        var idDiv = document.getElementById('projectQuery');
	        if(idDiv.style.display=='none'){
	            idDiv.style.display='block'; 
	        }else{
	           idDiv.style.display='none'; 
	        };
	    };
	    
	    //弹框，显示项目详细信息
	    function show_project_detail(id){
	    	AjaxUtil.request({
				url : 'show_project_detail.action',
				params : {id:id},
				success : function(responseText){
					//弹框放这
					PigossMsg.show("${pageContext.request.contextPath}/jsp/project/showProjectDetail.jsp","查看项目及客户信息",480,400,"");
				},
				failure : function(){
					PigossMsg.alert("修改失败!");
				}
			});
	    };
	    
	   
	    function isValid(){
	       var  dayStart=document.getElementById("dayStart").value;
	       var  dayEnd=document.getElementById("dayEnd").value;
	       if(dayStart!="7天前" && dayEnd!="现在"){
	           dayStart=dayStart.split("-");
		       dayEnd=dayEnd.split("-");
		       var timeStart=new Date(dayStart[0],dayStart[1],dayStart[2]);
		       var timeEnd=new Date(dayEnd[0],dayEnd[1],dayEnd[2]);
		       if(timeStart>=timeEnd){
		          PigossMsg.alert("开始时间必须小于结束时间！");
		          return false;
		       };
	        };
	    };
	    
	    initTableWidget('ptableSourt',['S','S',"S",'S','S','S',false,false,false]);

	</script>
    
    
    
  </body>
</html>
